﻿// owner 蒋家伟

#pragma once
#include <type_traits>
#include <vector>

// jsdk
#include "DBSchemaObject.h"

namespace jsdk
{
    template<unsigned int N>
    struct Number_Index : jsdk::Number_Index<N - 1> { unsigned int value{}; };
    template<>
    struct Number_Index<0> {};

    template<typename T>
    struct is_reflect_class
    {
        template<typename U, typename = std::enable_if_t<std::is_base_of<jsdk::DBSchemaObject, U>>>
        static constexpr bool check(typename U::this_is_reflect_class*) { return true; };
        template<typename U>
        static constexpr bool check(...) { return false; };
        static constexpr bool value = check<T>(nullptr);
    };

    struct default_type_imp
    {
        /// \ brief 字段反射函数
        template<typename This, typename Func>
        static inline void fieldReflect_iterate(const This&, Func&) {}
        template<typename Func>
        inline void fieldReflect_iterate(Func&) const {}

        /// \ brief 字段序列化函数
        template<typename This, typename Func>
        static inline bool fieldSerialize_iterate(const This&, Func&) { return true; }
        template<typename Func>
        inline bool fieldSerialize_iterate(Func&) const { return true; }
    };

    template <typename T, bool is_reflect = is_reflect_class<T>::value>
    struct reflect_class_adapter {
        using type = typename T;
    };

    template <typename T>
    struct reflect_class_adapter<T, false> {
        using type = typename default_type_imp;
    };
}
